' Diary
' This program maintains a computer diary in a sequential file.  The
'   diary can be printed on an Apple ImageWriter printer.

CLS

PRINT "The Secret Diary Program"
PRINT
INPUT "Enter the name of your diary file:  ", diary$
PRINT
INPUT "Is this a new diary file (Y/N)?  ", reply$

IF (UCASE$(reply$) = "Y") THEN
    OPEN diary$ FOR OUTPUT AS #1   ' open new file
 ELSE
    OPEN diary$ FOR APPEND AS #1   ' open existing file
END IF

PRINT
PRINT "Enter your secret thoughts for today; type END to quit."
PRINT

PRINT #1, TIME$; "  "; DATE$        ' write time and date to file
PRINT #1,                                       ' write blank line to file

' Until user types "END", get lines of text and write them to the file.

WHILE (UCASE$(text$) <> "END")
    LINE INPUT text$
    IF (text$ <> "END") THEN PRINT #1, text$
WEND
 
PRINT #1,                                       ' write blank line to file
CLOSE #1                                        ' close file

' Find out if user wants an Apple ImageWriter printout.

PRINT
INPUT "Would you like to print out your entire diary (Y/N)?  ", reply$

IF (UCASE$(reply$) = "Y") THEN     ' if yes,
    OPEN diary$ FOR INPUT AS #1  '   open file for input
   
    LPRINT STRING$(33, "-");         ' print a header at top of page
    LPRINT " My Diary ";
    LPRINT STRING$(33, "-")
    LPRINT                                      ' and a blank line

    ' Until end of file is reached, read lines from file and send them
    '   to the printer.
    
    WHILE (NOT EOF(1))
        LINE INPUT #1, text$
        LPRINT text$
    WEND

    CLOSE #1                                 ' close file
    LPRINT CHR$(12)                    ' send formfeed character

    ' Display message indicating diary contents have been sent to printer.
    
    PRINT
    INPUT "Diary sent to ImageWriter; press Return to continue", dummy$
END IF
